import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
// import monacoEditorPlugin from 'vite-plugin-monaco-editor'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '')
  return {
    plugins: [
      vue(),
      vueJsx()
      // monacoEditorPlugin({ languages: ['javascript', 'typescript', 'html', 'css', 'json'] })
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      host: '0.0.0.0',
      proxy: {
        [env.VITE_APP_BASE_API]: {
          target: env.VITE_SERVER,
          changeOrigin: true,
          rewrite: (path) =>
            path.replace(RegExp(`^${env.VITE_APP_BASE_API}`), '')
        },
        '/math': {
          target: 'http://localhost:3000', // 本地因证书问题暂不可用
          // target: 'https://www.liqiantw.icu:3000', // 云服务器
          // target: 'https://math-service-103217-5-1313428915.sh.run.tcloudbase.com', // 云托管
          changeOrigin: true,
          rewrite: (path) =>
            path.replace(RegExp('^/math'), '/')
        }
      }
    }
  }
})
